package com.hjw.rabbitmq.springbootorderrabbitmqproducer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class TTLRabbitMqConfiguration {

    @Bean
    public DirectExchange ttlDirectExchange(){return new DirectExchange("ttl_direct_exchange",true,false);}

    @Bean
    public Queue dirctttlQueue(){
        //设置过期时间  一般这是队列的过期时间
        Map<String,Object> map=new HashMap<>();
        map.put("x-message-ttl",5000);
        map.put("x-dead-letter-exchange","dead_direct_exchange");
        map.put("x-dead-letter-routing-key","dead");
        return new Queue("ttl_direct_queue",true,false,false,map);}

    @Bean
    public Queue dirctttlMessageQueue(){
        //非过期时间
        return new Queue("ttlMessage_direct_queue",true);}

    @Bean
    public Binding directttlBinding(){
        return  BindingBuilder.bind(dirctttlQueue()).to(ttlDirectExchange()).with("ttl");
    }
    @Bean
    public Binding directttlMessageBinding(){
        return BindingBuilder.bind(dirctttlMessageQueue()).to(ttlDirectExchange()).with("ttlmessage");
    }


}
